package com.example.sachon;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import  com.example.sachon.vo.*;
public class ChonSpinerAdapter implements SpinnerAdapter{
	private ArrayList<ChonInfo> data;
	private Context  context;
	private int textViewResourceId;
	public ChonSpinerAdapter(ArrayList<ChonInfo> data, int textViewResourceId,  Context  context){
        this.data = data;
        this.context = context;
        this.textViewResourceId = textViewResourceId;
    }
	 /**
     * Returns the Size of the ArrayList
     */
    @Override
    public int getCount() {
        return data.size();
    }

    /**
     * Returns one Element of the ArrayList
     * at the specified position.
     */
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return android.R.layout.simple_spinner_dropdown_item;
    }

    /**
     * Returns the View that is shown when a element was
     * selected.
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    android.R.layout.simple_spinner_item, parent, false);
        }
 
        TextView tv = (TextView) convertView
                .findViewById(android.R.id.text1);
        tv.setText(data.get(position).getChon_nm());
        tv.setTextColor(Color.BLUE);
        tv.setTextSize(12);
        return convertView;
    }
    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver observer) {
        // TODO Auto-generated method stub

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {
        // TODO Auto-generated method stub

    }

    /**
     * The Views which are shown in when the arrow is clicked
     * (In this case, I used the same as for the "getView"-method.
     */
    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
    	if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    android.R.layout.simple_spinner_dropdown_item, parent, false);
        }
 
        TextView input_name = (TextView) convertView
                .findViewById(android.R.id.text1);
        System.out.println("------------------------------");
        System.out.println("name::"+data.get(position).getChon_nm());
        System.out.println("name::"+input_name.toString());
        input_name.setText(data.get(position).getChon_nm());
        input_name.setTextColor(Color.RED);
        input_name.setTextSize(25);
        
        return this.getView(position, convertView, parent);
    }

}